<include file="Public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
  <include file="Public/breadcrumb"/>
    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 用户列表</h3>
                </div>
                <div class="panel-body">
                    <div class="navbar navbar-default">
                            <form action="" id="search-form2" class="navbar-form form-inline" method="post" onsubmit="return false">
								<?php
								if(session('fenbu_id')==0){
								?>
								<div class="form-group">
								 <select name="fenbu_id" id="fenbu_id" class="input-sm" style="width:100px;">
                                     <option value="">全部</option>
								 <foreach name="fenbu_list" item="v">
								 <option value="{$v['fenbu_id']}">{$v['fenbu_name']}</option>
								 </foreach>
								 </select>
								</div>
								<?php
								}else{
									echo '<input type="hidden" name="fenbu_id" id="fenbu_id" value="'.session('fenbu_id').'" />';
								}
								?>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" name="mobile" value="" placeholder="手机号码" id="mobile" class="form-control">
                                    </div>
                                </div>
                                 <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" name="user_id" value="" placeholder="用戶id" id="mobile" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" name="nickname" value="" placeholder="姓名/店铺" id="nickname" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" name="biaoshi" value="" placeholder="会员标识" id="biaoshi" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" name="biaoshi_xian" value="" placeholder="线路" id="biaoshi_xian" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" name="company_address" value="" placeholder="地址" id="company_address" class="form-control">
                                    </div>
                                </div>
								<div class="form-group">
								 <select name="gouwu" id="gouwu" class="input-sm" style="width:100px;">
								 <option value="">是否购物</option>
								 <option value="1">未购物</option>
								 <option value="2">已购物</option>
								 </select>
								</div>
                                <div class="form-group">
                                    <select name="fast_flag" id="fast_flag" class="input-sm" style="width:100px;">
                                        <option value="">是否快线</option>
                                        <option value="0">慢线</option>
                                        <option value="1">快线</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <select name="is_lock" id="is_lock" class="input-sm" style="width:100px;">
                                        <option value="">是否启动</option>
                                        <option value="1">是</option>
                                        <option value="2">否</option>
                                    </select>
                                </div>
								<div class="form-group">
								 <select name="salesman" id="salesman" class="input-sm" style="width:130px;">
								 <option value="">是否业务员</option>
								 <option value="2">否</option>
								 <option value="1">是</option>
								 </select>
								</div>
                                <div class="form-group">
                                    <select name="level" id="level" class="input-sm" style="width:100px;">
                                        <option value="">会员等级</option>
                                        <volist name="level_list" id="v">
                                            <option value="{$v['level_id']}">{$v['level_name']}</option>
                                        </volist>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" name="timegap" value="{:I('timegap')}" placeholder="注册日期"  id="add_time" class="input-sm" style="width: 220px;">
					                 </div>
                                </div>
                                 <div class="form-group">
                                    <input type="hidden" name="order_by" value="user_id">
                                	<input type="hidden" name="sort" value="desc">
                                	<button type="submit" onclick="ajax_get_table('search-form2',1,0)" id="button-filter search-order" class="btn btn-primary pull-right"><i class="fa fa-search"></i> 筛选</button>
                                 </div>
                                <button type="button" onclick="send_message(0);" class="btn btn-primary"><i class="fa"></i> 发送站内信</button>
                                <button type="button" onclick="save_user();" class="btn btn-primary"><i class="fa"></i> 批量修改会员</button>
                                <button type="button" onclick="send_mail();" class="btn btn-primary"><i class="fa"></i> 发送邮箱</button>

								 <a href="{:U('User/add_user')}" style="margin:0px 10px" class="btn btn-info pull-right">添加会员</a>

								 <button type="button"  class="btn btn-default pull-right" id="daochu"><i class="fa fa-file-excel-o"></i>&nbsp;导出excel</button>

                                 <!-- <button href="{:U('User/add_del')}" onclick="datadel()" class="btn btn-info pull-right">批量删除会员</button> -->

                            </form>
                    </div>
                    <div id="ajax_return">

                    </div>
                </div>
            </div>
        </div>        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<script>
    var is_driver = '{$is_driver}'
    var salesman = '{$salesman}'
    $(document).ready(function(){
        ajax_get_table('search-form2',1,0);

	 $("#daochu").click(function(){
		var mobile=$("#mobile").val(),
		nickname=$("#nickname").val(),
		gouwu=$("#gouwu").val(),
		biaoshi=$("#biaoshi").val(),
		timegap=$("#add_time").val(),
         biaoshi_xian=$("#biaoshi_xian").val();
		location.href='/index.php/Admin/user/export_user?mobile='+mobile+'&nickname='+nickname+'&biaoshi='+biaoshi+'&gouwu='+gouwu+"&timegap="+timegap+"&biaoshi_xian="+biaoshi_xian;
    });
    
    $('#add_time').daterangepicker({
			format:"YYYY-MM-DD HH:mm",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2021-01-01 00:00',
			maxDate:'2030-01-01 00:00',
			startDate:'{:date("Y-m-d")} 00:00',
	        showWeekNumbers: true,
	        timePicker: true,
	        timePickerIncrement: 1,
	        timePicker12Hour: false,
	        opens: 'right',
	        buttonClasses: ['btn btn-default'],
	        applyClass: 'btn-small btn-primary',
	        cancelClass: 'btn-small',
		    locale : {
	            applyLabel : '确定',
	            cancelLabel : '取消',
	            fromLabel : '起始时间',
	            toLabel : '结束时间',
	            customRangeLabel : '自定义',
	            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
	            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
	            firstDay : 1
	        }
		});
	});

    // ajax 抓取页面
    function ajax_get_table(tab,page,number){
        cur_page = page; //当前页面 保存为全局变量
            $.ajax({
                type : "POST",
                url:"/index.php/Admin/user/ajaxindex/p/"+page+"/n/"+number+"/is_driver/"+is_driver+"/salesman/"+salesman,//+tab,
                data : $('#'+tab).serialize(),// 你的formid
                success: function(data){
                    $("#ajax_return").html('');
                    $("#ajax_return").append(data);
                }
            });
    }

    // 点击排序
    function sort(field)
    {
        $("input[name='order_by']").val(field);
        var v = $("input[name='sort']").val() == 'desc' ? 'asc' : 'desc';
        $("input[name='sort']").val(v);
        ajax_get_table('search-form2',cur_page,0);
    }

    //发送站内信
    function send_message(id)
    {
        var obj = $("input[name*='selected']");
        var url = "{:U('Admin/User/sendMessage')}";
        if(obj.is(":checked")){
            var check_val = [];
            for(var k in obj){
                if(obj[k].checked)
                    check_val.push(obj[k].value);
            }
            url += "?user_id_array="+check_val;
        }
        layer.open({
            type: 2,
            title: '站内信',
            shadeClose: true,
            shade: 0.8,
            area: ['580px', '480px'],
            content: url
        });
    }
    //发送站内信
    function save_user(id)
    {
        var obj = $("input[name*='selected']");
        var url = "{:U('Admin/User/save_user')}";
        if(obj.is(":checked")){
            var check_val = [];
            for(var k in obj){
                if(obj[k].checked)
                    check_val.push(obj[k].value);
            }
            url += "?user_id_array="+check_val;
            layer.open({
                type: 2,
                title: '修改会员',
                shadeClose: true,
                shade: 0.8,
                area: ['960px', '680px'],
                content: url
            });
        }else{
            layer.msg('请选择会员');
        }
    }

    //发送邮件
    function send_mail()
    {
        var obj = $("input[name*='selected']");
        var url = "{:U('Admin/User/sendMail')}";
        if(obj.is(":checked")){
            var check_val = [];
            for(var k in obj){
                if(obj[k].checked)
                    check_val.push(obj[k].value);
            }
            url += "?user_id_array="+check_val;
            layer.open({
                type: 2,
                title: '发送邮箱',
                shadeClose: true,
                shade: 0.8,
                area: ['580px', '480px'],
                content: url
            });
        }else{
            layer.msg('请选择会员');
        }

    }

    /**
     * 回调函数
     */
    function call_back(v) {
        layer.closeAll();
        if (v == 1) {
            layer.msg('发送成功');
        } else {
            layer.msg('发送失败');
        }
    }
    /**
     * 回调函数
     */
    function call_backs(v) {
        layer.closeAll();
        if (v == 1) {
            layer.msg('修改完成');
        } else {
            layer.msg('修改失败');
        }
    }
</script>
</body>
</html>